<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <#include "/common/header.ftl">
    <title>活动管理</title>
</head>
<body>

<div id="activityDataGrid" style="width:100%;"></div>
<div id="toolBar">
    <table>
        <tr>
            <td>活动Id号:</td>
            <td>
                <input type="text" id="id">
            </td>
            <td>活动标题:</td>
            <td>
                <input type="text" id="actTitle">
            </td>
            <td>发布平台:</td>
            <td>
                <select class="easyui-combobox" id="actPublishPlatform" data-options="panelHeight:'auto',editable:false,required:true">
                    <option value="">请选择</option>
                    <option value="1">PC</option>
                    <option value="2">APP</option>
                    <option value="3">触屏版</option>
                </select>
            </td>
            <td>活动状态:</td>
            <td>
                <select class="easyui-combobox"  id="actStatus" data-options="panelHeight:'auto',editable:false,required:true">
                    <option value="">请选择</option>
                    <option value="0">未开始</option>
                    <option value="1">进行中</option>
                    <option value="2">已结束</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>建立时间</td>
            <td>
                <input type="text" id="createStartTime" class="easyui-datebox"/>
            </td>
            <td>---</td>
            <td>
                <input type="text" id="createEndTime"  class="easyui-datebox"/>
            </td>
        </tr>
        <tr>
            <td colspan="4">
                <center>
                    <shiro:hasPermission name="H01">
                        <shiro:hasPermission name="H0110">
                            <shiro:hasPermission name="H011001">
                                <a onclick="addActivity()" class="easyui-linkbutton"  iconCls="icon-add" >新建</a>
                            </shiro:hasPermission>
                            <shiro:hasPermission name="H011002">
                                <a onclick="doSearch()" class="easyui-linkbutton" iconCls="icon-search">查询</a>
                            </shiro:hasPermission>
                            <shiro:hasPermission name="H011003">
                                <a onclick="lookLink()" class="easyui-linkbutton" iconCls="icon-search">查看</a>
                            </shiro:hasPermission>
                            <shiro:hasPermission name="H011004">
                                <a onclick="editLink()" class="easyui-linkbutton" iconCls="icon-edit">修改</a>
                            </shiro:hasPermission>
                        </shiro:hasPermission>
                    </shiro:hasPermission>
                </center>
            </td>
        </tr>
    </table>
</div>
<!-- 新建活动 -->
<div id="add_activity_dialog"></div>
<div id="activity_dialog"></div>
<div id="statis_dialog" style="width:100%;"></div>
<script>
    $(function () {
        // 初始化数据表格
        refreshDataGrid();
    })

    /*
     * 点击查询按钮触发
     */
    function doSearch() {
        $('#activityDataGrid').datagrid('reload',{
            id: $('#id').val(),
            title: $('#actTitle').val(),
            rewardPoint:20,
            status:$('#actStatus').combobox("getValue"),
            publishPlatform:$('#actPublishPlatform').combobox("getValue"),
            createStartTime: $('#createStartTime').datebox("getValue"),
            createEndTime: $('#createEndTime').datebox("getValue")
        });
    }

    /**
     * 添加活动 按钮监听
     */
    function addActivity() {
        var url='/activity/addInvestNewActivityIndex';
        $('#add_activity_dialog').html("<iframe scrolling='yes' frameborder='0' src=" + url + " style='width:100%;height:100%;'></iframe>");
        $('#add_activity_dialog').dialog({
            title:'投资活动列表-->新建投资活动',
            modal: true,
            maximized:true,
            fit:true,
            width:'auto',
            height:'auto'
        });
    }

    /**
     * 渲染活动表格
     */
    function refreshDataGrid() {
        $("#activityDataGrid").datagrid({
            url: "/activity/queryActivitys",
            queryParams:{rewardPoint:20},
            loadMsg: "loading data...",
            fit:true,
            pagination: true,
            singleSelect:true,
            columns: [
                [
                    {field: 'id', title: '活动Id号',width:50, align: 'center'},
                    {field: 'title', title: '活动标题', fit:true, align: 'center'},
                    {field: 'publishPlatforms', title: '发布平台', fit:true, align: 'center'},
                    {field: 'investType', title: '投标类型', align: 'center',width:50,formatter:function(value,row,index){
                        if(value==1){
                            return "单次投标";
                        }else if(value==2){
                            return "总投标";
                        }
                    }
                    },
                    {field: 'weixinSendStatus', title: '微信消息发送状态', fit:true, align: 'center',formatter:function(value,row,index){
                        if(value==1){
                            return "已经发送";
                        }else{
                            return "尚未发送";}
                    }
                    },
                    {field: 'investAmount', title: '投资金额(元)', fit:true, align: 'center'},
                    {field: 'borrowTypes', title: '可投标类型', fit:true, align: 'center'},
                    {field: 'ticketId', title: '奖池Id', fit:true, align: 'center'},
                    {field: 'registerStart', title: '开始时间', fit:true, align: 'center'},
                    {field: 'registerEnd', title: '结束时间', fit:true, align: 'center'},
                    {field: 'createTime', title: '创建时间', fit:true, align: 'center'},
                    {field: 'status', title: '状态', align: 'center',width:50,formatter:function(value,row,index){
                        if(value==0){
                            return "未生效";
                        }else if(value==1){
                            return "生效";
                        }else if(value==2){
                            return "失效";
                        }else{
                            return "";}
                    }
                    },
                    {field: 'statistics',title:'统计',align:'center',width:100,formatter:function(value,row,index){
                        return "<a href='javascript:void(0);' onclick='activityStatistics(\""+row.id+"\");'>统计</a>";
                    }
                    }
                ]
            ],
            onLoadSuccess:function(data){
                if (data.errorMsg){
                    $.messager.alert('错误',data.errorMsg);
                }
            },
            onLoadError:function(){
                $.messager.alert('错误',"错误");

            },
            toolbar: "#toolBar"
        });
    }
    function searchActTitle(){
        var userName = $("#title").val();
        if(userName != ""){
            $.post('/activity/checkActivityTitle',{title:$("#title").val()},function(result){
                if (result.code == -1 ){
                    $.messager.alert('提示',result.msg,'info',function(){
                        $("#userName").val("");
                    });
                }
            },'json');

        }
    }

    function lookLink(){
        var row = $('#activityDataGrid').datagrid('getSelected');
        if (row==null){
            $.messager.alert('提示',"请选择一条记录！");
        }else{
            activityDetail(row.id,"SHOW","NO");
        }
    }

    /**
     * 活动详细信息
     */
    function activityDetail(id,flag,status){
        if (id!=null&&id!=""&&flag!=null&&flag!=""){
            var url = '/activity/activityDetail?id='+id+'&editFlag='+flag;
            $('#activity_dialog').html("<iframe width='1200' height='600'	scrolling='yes'  src='"+url+"'></iframe>");
            $('#activity_dialog').dialog({
                title:'活动信息',
                modal: true,
                width:'auto',
                height:'auto'
            });
        }
    }

    function closeDetailWin(){
        $('#activity_dialog').dialog('close');
        doSearch();
    }

    function editLink(){
        var row = $('#activityDataGrid').datagrid('getSelected');
        if (row==null){
            $.messager.alert('提示',"请选择一条记录！");
        }else{
            activityDetail(row.id,"EDIT",row.approvalStatus);
        }
    }

    function closeAddWin(){
        $('#add_activity_dialog').dialog('close');
        doSearch();
    }

    function activityStatistics(id){
        if(id!=null && id!=""){
            var url='/activity/investActStatisIndex?id='+id;
            $('#statis_dialog').html("<iframe width='1300' height='800' frameborder=0  src='"+url+"'></iframe>");
            $('#statis_dialog').dialog({
                title:'活动统计',
                modal: true,
                width:'auto',
                height:'auto'
            });
        }
    }
</script>
</body>
</html>